package cn.hrbnu.web;

import cn.hrbnu.service.UploadService;
import cn.hrbnu.util.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhangyadong
 * @version 1.0
 * &#064;ClassName  UploadController
 * &#064;date  2025-06-16 17:02
 */

@RestController
public class UploadController {


    private final UploadService uploadService;

    public UploadController(UploadService uploadService) {
        this.uploadService = uploadService;
    }


    /**
     * 上传图片接口
     * <p>
     * 该方法通过POST请求接收一个名为"img"的multipart/form-data格式的图片文件，
     * 并调用uploadService的upload方法进行图片上传处理
     *
     * @param img 要上传的图片文件，类型为MultipartFile
     * @return 返回上传结果，类型为ResponseResult，包含上传成功或失败的信息
     */
    @PostMapping("/upload")
    public ResponseResult<Object> upload(MultipartFile img) {
        return uploadService.upload(img);
    }
}